package com.psp.park.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.park.model.DemandBean;
import com.psp.park.persist.dao.DemandDao;

@Repository
public class DemandImpl extends BaseImpl implements DemandDao {

	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".DemandMapper";

	@Override
	public int selectCount(String puid, int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		where.put("uid", puid);
		where.put("cateCode", cateCode);
		where.put("content", content);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public List<DemandBean> selectList(int page, int pageSize, String puid, int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		where.put("uid", puid);
		where.put("cateCode", cateCode);
		where.put("content", content);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int deleteById(List<String> dids) {
		Map<String, Object> where = new HashMap<>();
		where.put("dids", dids);
		return sqlSessionTemplate.delete(NAME_SPACE + ".updateDemandState", where);
	}

	@Override
	public int insert(DemandBean bean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", bean);
	}

	@Override
	public int update(DemandBean bean) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", bean);
	}


}
